package com.bdzl.biz.controller;

import com.bdzl.biz.service.OrderPayAccountService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.loan.OrderPayAccountDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 订单打款账户信息表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-24 11:25:01
 */

@Controller
@RequestMapping("/bdzl/orderPayAccount")
public class OrderPayAccountController extends BaseController {
	@Autowired
	private OrderPayAccountService orderPayAccountService;

	@GetMapping()
	String OrderPayAccount(){
	    return "bdzl/orderPayAccount/orderPayAccount";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OrderPayAccountDO> orderPayAccountList = orderPayAccountService.list(query);
		int total = orderPayAccountService.count(query);
		PageUtils pageUtils = new PageUtils(orderPayAccountList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/orderPayAccount/add";
	}

	@GetMapping("/edit/{payId}")
	String edit(@PathVariable("payId") Integer payId,Model model){
		OrderPayAccountDO orderPayAccount = orderPayAccountService.get(payId);
		model.addAttribute("orderPayAccount", orderPayAccount);
	    return "bdzl/orderPayAccount/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( OrderPayAccountDO orderPayAccount){
		if(orderPayAccountService.save(orderPayAccount)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( OrderPayAccountDO orderPayAccount){
		orderPayAccountService.update(orderPayAccount);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer payId){
		if(orderPayAccountService.remove(payId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] payIds){
		orderPayAccountService.batchRemove(payIds);
		return R.ok();
	}

}
